package tp.pr5;

import tp.pr5.commands.Command;
import tp.pr5.commands.exceptions.CommandExecutionException;
import tp.pr5.commands.exceptions.WrongCommandFormatException;

@SuppressWarnings("unused")
public abstract class GameController {
	
	protected Game _game;
	protected String mode;
	
	//contructor
	public GameController(Game game){
		
		this._game=game;		
	}
	
	public  void registerGameObserver(GameObserver gameObserver)
	{
		this._game.addGameObserver(gameObserver);
	}
	//Registers a GameObserver to the model
	public void	registerMapObserver(MapObserver mapObserver)
	{
		this._game.addMapObserver(mapObserver);
	}
	//Registers a MapObserver to the model
	public void	registerPlayerObserver(PlayerObserver playerObserver)
	{
		this._game.addPlayerObserver(playerObserver);
	}
	//Registers a PlayerObserver to the model
	public String executeStep(String line)
	{
		String message;
		try
		{
		/*	if (game.isOver() || this._friki.dead())
				message= MensajesConst.adios;
			else {*/
			Command auxCommand = Parser.parseCommand(line);
			this._game.executeCommand(auxCommand);
			message= null;

			//}
		} catch (WrongCommandFormatException e)
		{
			message= MensajesConst.what;
			this._game.requestError(message);
			
		}
		//if (message!=null)
	//		JOptionPane.showMessageDialog(null, message);
	return message;
	}
	public abstract void runGame();
	//Abstract method that runs the game.

}